/*
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2006-2007 Intel Corporation. All Rights Reserved.
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_DV_VIDEO_ENCODER)

#ifndef __SEGMENT_COMPRESSOR_H
#define __SEGMENT_COMPRESSOR_H

#include "umc_structures.h"
#include "umc_memory_allocator.h"

namespace UMC
{

struct V_SEGMENT
{
    struct BLOCK *m_pDCTBlocks;                      // (BLOCK *) pointer to array of 30 or 40 macroblocks
    Ipp8s *m_lpcBuffer;                              // pionter to memory block, which has DCT blocks
    V_SEGMENT(){m_lpcBuffer = 0; m_pDCTBlocks = 0;}
};

class SegmentCompressor
{
public:
    SegmentCompressor();
    virtual ~SegmentCompressor();

    // init segment compressor
    Status InitCompressor(int iDCTBlocksInMB, MemoryAllocator *pMemoryAllocator);

    // compress DV segment
    virtual void CompressSegment(struct DV_SEGMENT *lpDVSegment);

    void LockWorkBuffers();
    void UnlockWorkBuffers();

    // release segment compressor
    void ReleaseCompressor();

    void ResetEncodeBitStream();

    V_SEGMENT m_VSegment;                           // (V_SEGMENT) video data

    struct ENCODE_BIT_STREAM *m_Streams;            // (ENCODE_BIT_STREAM *) pointer to array of bitstreams

    struct ENCODE_BIT_STREAM *(m_MStreamsE[5]);     // (ENCODE_BIT_STREAM *) pointers to stream, which has free bits
    struct ENCODE_BIT_STREAM *(m_MStreamsF[5]);     // (ENCODE_BIT_STREAM *) pointers to stream, which has extra bits
    struct ENCODE_BIT_STREAM *m_VStreamsE;          // (ENCODE_BIT_STREAM *) pointer to stream, which has free bits
    struct ENCODE_BIT_STREAM *m_VStreamsF;          // (ENCODE_BIT_STREAM *) pointer to stream, which has extra bits

    Ipp8u *m_lpbBuffer;                             // (Ipp8u *) pointer to buffer for ENCODE_BIT_STREAM
    Ipp8u *m_lpbBitSequences;                       // (Ipp8u *) pointer to buffer for bit sequences

protected:
    void DoDCT();
    void ZigZagData();
    void QuantizeData(struct DV_SEGMENT *lpDVSegment);
    void EncodeHuffman(struct DV_SEGMENT *lpDVSegment);
    void QuantizeBlock(BLOCK *lpBlock, Ipp32u qno);

    Ipp32s m_nDCTBlocksInMB;
    Ipp32s *m_DCTBlockLengths;

    MemoryAllocator *m_pMemoryAllocator;
    MemID  m_DCTBlocksBufMID;
    MemID  m_BitSeqBufMID;
    Ipp8u  m_bQuantPredictor;
};

}//namespace UMC

#endif //__SEGMENT_COMPRESSOR_H

#endif //(UMC_ENABLE_DV_VIDEO_ENCODER)
